<?php
declare (strict_types = 1);

namespace app\middleware;
use app\Token;
class checkToken
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
		  //第一步先取token
		    $token = $request->header('Authorization');
		    //jwt进行校验token
		    $res = (new Token())->chekToken($token);
		    if ($res['code'] != 1 ){
		   
		      return json(['code'=>401,'msg'=>$res['msg'],'data'=>''],401);
		    }
		    $request->uid = $res['data']->uid;
		    return $next($request);
    }
}
